package program.conditions;

import be.kuleuven.cs.som.annotate.*;
import item.*;
/**
 * A class concerning not-conditions: (not(condition)).  
 *
 * @invar	The condition of each not-condition must be a valid condition.
 *                      | canHaveAsCondition(getCondition())
 *
 */
public class Not extends Conditions {
	private final Conditions conditions;
	
	/**
	 * Initialise this new not-condition with a line number and a condition.
	 *
	 * @param	conditions
	 *                      The conditions to be evaluated.
	 * @pre		The given condition must be a valid one.
	 *                      | canHaveAsConditions(conditions)
	 * @post     The given conditions are set as the condition of this not-condition.
	 *                      | new.getCondition() == condition
	 */
	public Not(int lineNb, Conditions conditions) {
		super(lineNb);
		assert( canHaveAsConditions(conditions) );
		this.conditions = conditions;
	}
	
	/**
	 * Returns the conditions to be evaluated.
	 */
	@Basic @Raw @Immutable
	public Conditions getConditions() {
		return conditions;
	}
	/**
	 * Checks whether the given conditions are valid for a not-condition.
	 *
	 * @param	condition
	 *                      The condition to check for whether it is a valid one.
	 * @return     
	 * 			| result == ( condition != null )
	 */
	@Raw
	public boolean canHaveAsConditions(Conditions conditions) {
		return ( conditions != null );
	}
	
	/**
	 * Evaluate these conditions for a given robot.
	 *
	 * @return		
	 * 			| result == ( super.evaluate(robot) &&
	 *          |                               ! condition.evaluate(robot) )
	 */
	@Override
	public boolean evaluate(Robot robot) {
		return ( super.evaluate(robot) && ! conditions.evaluate(robot));
	}
	
	/**
	 * Return a textual representation of this not-condition,
	 * formatted in accordance with its position in the program.
	 *
	 * @return	
	 *         | result == getIndentation(indentationLevel) + "(not\n" +
	 *         |            getCondition().getIndentation(indentationLevel+1) + "\n)"
	 */
	@Override
	public String prettyFormat(int indentationLevel) {
		return getIndentation(indentationLevel) + "(not\n" +
				getConditions().getIndentation(indentationLevel+1) + "\n)";
	}
} 
